<?php
namespace app\common\lib\module_config;

use app\common\lib\model_operate\Trace;
use app\common\lib\module_config\TagRW;

/**
 * 标签配置父类
 */
abstract class TagsConfig
{
    protected $config; //配置信息

    protected $trace; //追踪信息

    protected $tags; //标签名

    protected $fields; //字段配置信息

    //标签映射
    private $tagMap = [
        ' eq '    => ' = ',
        ' neq '   => ' <> ',
        ' gt '    => ' > ',
        ' egt '   => ' >= ',
        ' lt '    => ' < ',
        ' elt '   => ' <= ',
        ' lk '    => ' LIKE ',
        ' null '  => ' IS NULL ',
        ' unull ' => ' IS NOT NULL ',
    ];

    public function __construct(Trace $trace, $tags)
    {
        $this->setTrace($trace);
        $this->setConfig($tags);
    }

    /**
     * 设置追踪信息
     */
    final public function setTrace(Trace $trace)
    {
        $this->trace = $trace;
    }

    /**
     * 获取配置
     */
    final public function setConfig($tags)
    {
        //设置标签名
        $this->tags = $tags;
        //调用获取配置方法获取配置
        $this->config = TagRW::traceConfig($this->trace, $tags);
        //获取字段配置信息
        if (isset($this->config['fields']) && !empty($this->config['fields'])) {
            $this->fields = $this->config['fields'];
        }
    }

    /**
     * 获取标签映射
     */
    public function getTagMap()
    {
        return $this->tagMap;
    }

    /**
     * 创建html
     * 子级根据配置实现创建html信息
     */
    abstract public function createHtml();

    /**
     * 设置动态参数
     */
    abstract public function setParam();

}
